

/**************************************TRIM IN JAVASCRIPT STARTS FROM HERE************************************************/
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}

/************************************************TRIM IN JAVASCRIPT ENDS HERE*******************************************/

function ChangeCountryStateCity(ServerScripT,CountryId,StateId,CityId,Type)
{
	if(Type == "COUNTRY")
	{
		if(document.getElementById(CountryId) != null)
		{
			var CountrYId=document.getElementById(CountryId).value;
			//alert(ServerScripT+"--CountryId="+CountrYId +'--StateId='+StateId+'--CityId='+CityId+'--Type='+Type);
			//alert(CountrYId)
			if(CountrYId != 0)
			{
				document.getElementById(CountryId).style.display='';
				/*document.getElementById(CountryId+'1').style.display='';
				document.getElementById(CountryId+'1').disabled=true;*/
				if(document.getElementById(CountryId+'1') != null)
				{
					document.getElementById(CountryId+'1').style.display='none';
				}
				if(document.getElementById(CountryId+'1') != null)
				{
					document.getElementById(CountryId+'1').disabled=true;
				}
				if(document.getElementById(Type+'1') != null)
				{
					document.getElementById(Type+'1').style.display='none';
				}
				
				/********************************* FOR STATE **************************************/ 
				if(document.getElementById('StaTeSELECT1') != null && document.getElementById('STATE1') != null)
				{
					document.getElementById('StaTeSELECT1').disabled=true;
					document.getElementById('STATE1').style.display='none';
				}
				
				if(document.getElementById('StaTeSELECT') != null && document.getElementById('STATE') != null)
				{
					document.getElementById('StaTeSELECT').disabled=false;
					document.getElementById('STATE').style.display='';
				}
				/********************************* FOR CITY **************************************/ 
				if(document.getElementById('CiTySelect1') != null && document.getElementById('CITY1') != null)
				{
					document.getElementById('CiTySelect1').disabled=true;
					document.getElementById('CITY1').style.display='none';
				}
				
				if(document.getElementById('CiTySelect') != null && document.getElementById('CITY') != null)
				{
					document.getElementById('CiTySelect').disabled=false;
					document.getElementById('CITY').style.display='';
				}
				sendReqTObackENDTOexeCUTE(ServerScripT,"CountryId="+CountrYId);
			
			}
			else
			{
				//alert("asdasdasdas");
				/*alert(CountryId);
				alert(document.getElementById(CountryId));
				alert(document.getElementById(CountryId+'1'));
				alert(document.getElementById(Type+'1'));*/
				if(document.getElementById(CountryId+'1') != null)
				{
					document.getElementById(CountryId+'1').style.display='';
				}
				if(document.getElementById(CountryId+'1') != null)
				{
					document.getElementById(CountryId+'1').disabled=false;
				}
				if(document.getElementById(Type+'1') != null)
				{
					document.getElementById(Type+'1').style.display='';
				}
				/********************************* FOR STATE **************************************/
				//alert(document.getElementById('StaTeSELECT1'));
				//alert(document.getElementById('STATE1'));
				if(document.getElementById('StaTeSELECT1') != null && document.getElementById('STATE1') != null)
				{
					document.getElementById('StaTeSELECT1').disabled=false;
					document.getElementById('STATE1').style.display='';
				}
				
				if(document.getElementById('StaTeSELECT') != null && document.getElementById('STATE') != null)
				{
					document.getElementById('StaTeSELECT').disabled=true;
					document.getElementById('STATE').style.display='none';
				}
				/********************************* FOR CITY **************************************/ 
				if(document.getElementById('CiTySelect1') != null && document.getElementById('CITY1') != null)
				{
					document.getElementById('CiTySelect1').disabled=false;
					document.getElementById('CITY1').style.display='';
				}
				
				if(document.getElementById('CiTySelect') != null && document.getElementById('CITY') != null)
				{
					document.getElementById('CiTySelect').disabled=true;
					document.getElementById('CITY').style.display='none';
				}
			}
		}
	}
	if(Type == "STATE")
	{
		//alert("sadlkaskldjask")
		if(document.getElementById(CountryId) != null && document.getElementById(StateId) != null )
		{
			var CountrYId=document.getElementById(CountryId).value;
			var StatEId=document.getElementById(StateId).value;
			//alert("CountryId="+CountrYId+"&StateId="+StatEId)
			sendReqTObackENDTOexeCUTE(ServerScripT,"CountryId="+CountrYId+"&StateId="+StatEId);
		}
	}
	if(Type == "CITY")
	{
		if(document.getElementById(CountryId) != null && document.getElementById(StateId) != null && document.getElementById(CityId) != null )
		{
			var CountrYId=document.getElementById(CountryId).value;
			var StatEId=document.getElementById(StateId).value;
			var CitYId=document.getElementById(CityId).value;
			sendReqTObackENDTOexeCUTE(ServerScripT,"CountryId="+CountrYId+"&StateId="+StatEId+"&CityId="+CitYId);
		}
	}
	
}



function formvalidation()
{
	
	var NameVAlidation=/[0-9\*\=\_\>\<\:\@\&\%\?\$\-\/\!\^\(\)\{\}\|\~\`\'\"\;\,\.\+\#\\]/;
	var USERNameVAlidation=/[\*\=\_\>\<\:\@\&\%\?\$\-\/\!\^\(\)\{\}\|\~\`\'\"\;\,\.\+\#\\]/;
	var EmailVALIdation=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var PhonEVAlidation=/[a-zA-Z\*\=\_\>\<\:\@\&\%\?\$\/\!\^\(\)\{\}\|\~\`\'\"\;\,\.\\]/;
	var AddressvalIDAtiON=/[\*\=\_\>\<\:\@\&\%\?\$\!\^\(\)\{\}\|\~\`\"\;\.\+\#\\]/;
	var ZIpVAlidation=/[\*\=\_\>\<\:\@\&\%\?\$\-\/\!\^\(\)\{\}\|\~\`\'\"\;\,\.\+\#\\]/;
	var RETURnvalUE=false;

	
	if(document.getElementById("FirstName") != null)
	{
		if(document.getElementById("FirstName").value != '')
		{
			//alert(document.getElementById("FirstName").value)
			//alert(document.getElementById("FirstName").value.search(NameVAlidation))
			if(document.getElementById("FirstName").value.search(NameVAlidation) >= 0 )
			{
				document.getElementById("FirstNameError").innerHTML="<br>Your First Name Should Be Only Charecters.";
				document.getElementById("FirstNameError").style.display='';
				document.getElementById("FirstName").ClassName="RedClass";
				document.getElementById("FirstName").focus();
				return false;
			}
			var str =Trim(document.getElementById("FirstName").value);
			if( str=='')
			{
				document.getElementById("FirstNameError").innerHTML="<br>Please Dont Give Space In First Name Field.";
				document.getElementById("FirstNameError").style.display='';
				document.getElementById("FirstName").ClassName="RedClass";
				document.getElementById("FirstName").value="";
				document.getElementById("FirstName").focus();
				return false;
			}
			else
			{
				document.getElementById("FirstNameError").innerHTML="";
				document.getElementById("FirstNameError").style.display='none';
				document.getElementById("FirstName").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("FirstNameError") != null)
			{
				document.getElementById("FirstNameError").innerHTML="<br>Please Type Your First Name.";
				document.getElementById("FirstNameError").style.display='';
				document.getElementById("FirstName").ClassName="RedClass";
				document.getElementById("FirstName").focus();
				return false;
			}
		}
	}



	if(document.getElementById("LastName") != null)
	{
		if(document.getElementById("LastName").value != '')
		{
			if(document.getElementById("LastName").value.search(NameVAlidation) >= 0)
			{
				document.getElementById("LastNameError").innerHTML="<br>Your Last Name Should Be Only Charecters.";
				document.getElementById("LastNameError").style.display='';
				document.getElementById("LastName").ClassName="RedClass";
				document.getElementById("LastName").focus();
				return false;
			}
			var str =Trim(document.getElementById("LastName").value);
			if( str=='')
			{
				document.getElementById("LastNameError").innerHTML="<br>Please Dont Give Space In Last Name Field.";
				document.getElementById("LastNameError").style.display='';
				document.getElementById("LastName").ClassName="RedClass";
				document.getElementById("LastName").value="";
				document.getElementById("LastName").focus();
				return false;
			}
			else
			{
				document.getElementById("LastNameError").innerHTML="";
				document.getElementById("LastNameError").style.display='none';
				document.getElementById("LastName").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("LastNameError") != null)
			{
				document.getElementById("LastNameError").innerHTML="<br>Please Type Your Last Name.";
				document.getElementById("LastNameError").style.display='';
				document.getElementById("LastName").ClassName="RedClass";
				document.getElementById("LastName").focus();
				return false;
			}
		}
	}



	if(document.getElementById("EmaiL") != null)
	{
		if(document.getElementById("EmaiL").value != '')
		{
			if(!EmailVALIdation.test(document.getElementById("EmaiL").value))
			{
				document.getElementById("EmaiLError").innerHTML="<br>Invalid Email Address.";
				document.getElementById("EmaiLError").style.display='';
				document.getElementById("EmaiL").ClassName="RedClass";
				document.getElementById("EmaiL").focus();
				return false;
			}
			var str =Trim(document.getElementById("EmaiL").value);
			if( str=='')
			{
				document.getElementById("EmaiLError").innerHTML="<br>Please Dont Give Space In Email Field.";
				document.getElementById("EmaiLError").style.display='';
				document.getElementById("EmaiL").ClassName="RedClass";
				document.getElementById("EmaiL").value="";
				document.getElementById("EmaiL").focus();
				return false;
			}
			else
			{
				document.getElementById("EmaiLError").innerHTML="";
				document.getElementById("EmaiLError").style.display='none';
				document.getElementById("EmaiL").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("EmaiLError") != null)
			{
				document.getElementById("EmaiLError").innerHTML="<br>Please Type Your Email.";
				document.getElementById("EmaiLError").style.display='';
				document.getElementById("EmaiL").ClassName="RedClass";
				document.getElementById("EmaiL").focus();
				return false;
			}
		}
	}


	if(document.getElementById("ADD") != null)
	{

		if(document.getElementById("ADD").value != '')
		{
			if(document.getElementById("ADD").value.search(AddressvalIDAtiON) >= 0)
			{
				document.getElementById("ADDError").innerHTML="<br>Please Give Proper Address.";
				document.getElementById("ADDError").style.display='';
				document.getElementById("ADD").ClassName="RedClass";
				document.getElementById("ADD").focus();
				return false;
			}
			var str =Trim(document.getElementById("ADD").value);
			if( str=='')
			{
				document.getElementById("ADDError").innerHTML="<br>Please Dont Give Space In Address Field.";
				document.getElementById("ADDError").style.display='';
				document.getElementById("ADD").ClassName="RedClass";
				document.getElementById("ADD").value="";
				document.getElementById("ADD").focus();
				return false;
			}
			else
			{
				document.getElementById("ADDError").innerHTML="";
				document.getElementById("ADDError").style.display='none';
				document.getElementById("ADD").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("ADDError") != null)
			{
				document.getElementById("ADDError").innerHTML="<br>Please Type Your Address.";
				document.getElementById("ADDError").style.display='';
				document.getElementById("ADD").ClassName="RedClass";
				document.getElementById("ADD").focus();
				return false;
			}
		}

	}


	if(document.getElementById("CounTrySELECT") != null && document.getElementById("COUNTRY").style.display != 'none')
	{
		//alert(document.getElementById("CounTrySELECT").value)
		if(document.getElementById("CounTrySELECT").value == '' || document.getElementById("CounTrySELECT").value == undefined)
		{
			if(document.getElementById("CounTrySELECT") != null)
			{
				document.getElementById("CounTrySELECTError").style.display='';
				document.getElementById("CounTrySELECTError").innerHTML="<br>Please Select A Country.";
				document.getElementById("CounTrySELECT").ClassName="RedClass";
				document.getElementById("CounTrySELECT").focus();
				return false;
			}
		}
		else
		{
			document.getElementById("CounTrySELECTError").innerHTML="";
			document.getElementById("CounTrySELECTError").style.display='none';
			document.getElementById("CounTrySELECT").ClassName="NormalClass";
			//document.getElementById("CounTrySELECT").focus();
		}
	}



	if(document.getElementById("CounTrySELECT1") != null && document.getElementById("COUNTRY1").style.display == '')
	{
		if(document.getElementById("CounTrySELECT1").value != '')
		{
			if(document.getElementById("CounTrySELECT1").value.search(NameVAlidation) >= 0)
			{
				document.getElementById("CounTrySELECTError").innerHTML="<br>Your Country Should Be Only Charecters.";
				document.getElementById("CounTrySELECTError").style.display='';
				document.getElementById("CounTrySELECT1").ClassName="RedClass";
				document.getElementById("CounTrySELECT1").focus();
				return false;
			}
			var str =Trim(document.getElementById("CounTrySELECT1").value);
			if( str=='')
			{
				document.getElementById("CounTrySELECTError").innerHTML="<br>Please Dont Give Space In Country Field.";
				document.getElementById("CounTrySELECTError").style.display='';
				document.getElementById("CounTrySELECT1").ClassName="RedClass";
				document.getElementById("CounTrySELECT1").value="";
				document.getElementById("CounTrySELECT1").focus();
				return false;
			}
			else
			{
				document.getElementById("CounTrySELECTError").innerHTML="";
				document.getElementById("CounTrySELECTError").style.display='none';
				document.getElementById("CounTrySELECT1").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("CounTrySELECTError") != null)
			{
				document.getElementById("CounTrySELECTError").innerHTML="<br>Please Type Your Country.";
				document.getElementById("CounTrySELECTError").style.display='';
				document.getElementById("CounTrySELECT1").ClassName="RedClass";
				document.getElementById("CounTrySELECT1").focus();
				return false;
			}
		}
	}



	if(document.getElementById("StaTeSELECT") != null && document.getElementById("STATE").style.display == '')
	{
		//alert(document.getElementById("StaTeSELECT").value)
		if(document.getElementById("StaTeSELECT").value == '' || document.getElementById("StaTeSELECT").value == undefined)
		{
			if(document.getElementById("StaTeSELECT") != null)
			{
				document.getElementById("StaTeSELECTError").innerHTML="<br>Please Select A State.";
				document.getElementById("StaTeSELECTError").style.display='';
				document.getElementById("StaTeSELECT").ClassName="RedClass";
				document.getElementById("StaTeSELECT").focus();
				return false;
			}
		}
		else
		{
			document.getElementById("StaTeSELECTError").innerHTML="";
			document.getElementById("StaTeSELECTError").style.display='none';
			document.getElementById("StaTeSELECT").ClassName="NormalClass";
			//document.getElementById("StaTeSELECT").focus();
		}
	}



	if(document.getElementById("StaTeSELECT1") != null && document.getElementById("STATE1").style.display == '')
	{
		if(document.getElementById("StaTeSELECT1").value != '')
		{
			if(document.getElementById("StaTeSELECT1").value.search(NameVAlidation) >= 0)
			{
				document.getElementById("StaTeSELECTError").innerHTML="<br>Your State Should Be Only Charecters.";
				document.getElementById("StaTeSELECTError").style.display='';
				document.getElementById("StaTeSELECT1").ClassName="RedClass";
				document.getElementById("StaTeSELECT1").focus();
				return false;
			}
			var str =Trim(document.getElementById("StaTeSELECT1").value);
			if( str=='')
			{
				document.getElementById("StaTeSELECTError").innerHTML="<br>Please Dont Give Space In State Field.";
				document.getElementById("StaTeSELECTError").style.display='';
				document.getElementById("StaTeSELECT1").ClassName="RedClass";
				document.getElementById("StaTeSELECT1").value="";
				document.getElementById("StaTeSELECT1").focus();
				return false;
			}
			else
			{
				document.getElementById("StaTeError").innerHTML="";
				document.getElementById("StaTeError").style.display='none';
				document.getElementById("StaTe1").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("StaTeError") != null)
			{
				document.getElementById("StaTeError").innerHTML="<br>Please Type Your State.";
				document.getElementById("StaTeError").style.display='';
				document.getElementById("StaTe1").ClassName="RedClass";
				document.getElementById("StaTe1").focus();
				return false;
			}
		}
	}



	if(document.getElementById("CiTySelect") != null && document.getElementById("CITY").style.display == '')
	{
		if(document.getElementById("CiTySelect").value == '' || document.getElementById("CiTySelect").value == undefined)
		{
			if(document.getElementById("CiTySelect") != null)
			{
				document.getElementById("CiTySelectError").innerHTML="<br>Please Select A City.";
				document.getElementById("CiTySelectError").style.display='';
				document.getElementById("CiTySelect").ClassName="RedClass";
				document.getElementById("CiTySelect").focus();
				return false;
			}
		}
		else
		{
			document.getElementById("CiTySelectError").innerHTML="";
			document.getElementById("CiTySelectError").style.display='none';
			document.getElementById("CiTySelect").ClassName="NormalClass";
			//document.getElementById("CiTySelect").focus();
		}
	}



	if(document.getElementById("CiTySelect1") != null && document.getElementById("CITY1").style.display == '')
	{
		if(document.getElementById("CiTySelect1").value != '')
		{
			if(document.getElementById("CiTySelect1").value.search(NameVAlidation) >= 0)
			{
				document.getElementById("CiTySelectError").innerHTML="<br>Your Country Should Be Only Charecters.";
				document.getElementById("CiTySelectError").style.display='';
				document.getElementById("CiTySelect1").ClassName="RedClass";
				document.getElementById("CiTySelect1").focus();
				return false;
			}
			var str =Trim(document.getElementById("CiTySelect1").value);
			if( str=='')
			{
				document.getElementById("CiTySelectError").innerHTML="<br>Please Dont Give Space In Country Field.";
				document.getElementById("CiTySelectError").style.display='';
				document.getElementById("CiTySelect1").ClassName="RedClass";
				document.getElementById("CiTySelect1").value="";
				document.getElementById("CiTySelect1").focus();
				return false;
			}
			else
			{
				document.getElementById("CiTySelectError").innerHTML="";
				document.getElementById("CiTySelectError").style.display='none';
				document.getElementById("CiTySelect1").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("CiTySelectError") != null)
			{
				document.getElementById("CiTySelectError").innerHTML="<br>Please Type Your Country.";
				document.getElementById("CiTySelectError").style.display='';
				document.getElementById("CiTySelect1").ClassName="RedClass";
				document.getElementById("CiTySelect1").focus();
				return false;
			}
		}
	}



	if(document.getElementById("ZIpcoDE") != null)
	{
		if(document.getElementById("ZIpcoDE").value != '')
		{
			if(document.getElementById("ZIpcoDE").value.search(ZIpVAlidation) >= 0)
			{
				document.getElementById("ZIpcoDEError").innerHTML="<br>Your Zipcode Should Be Only Charecters And Numeric.";
				document.getElementById("ZIpcoDEError").style.display='';
				document.getElementById("ZIpcoDE").ClassName="RedClass";
				document.getElementById("ZIpcoDE").focus();
				return false;
			}
			var str =Trim(document.getElementById("ZIpcoDE").value);
			if( str=='')
			{
				document.getElementById("ZIpcoDEError").innerHTML="<br>Please Dont Give Space In Zipcode Field.";
				document.getElementById("ZIpcoDEError").style.display='';
				document.getElementById("ZIpcoDE").ClassName="RedClass";
				document.getElementById("ZIpcoDE").value="";
				document.getElementById("ZIpcoDE").focus();
				return false;
			}
			else
			{
				document.getElementById("ZIpcoDEError").innerHTML="";
				document.getElementById("ZIpcoDEError").style.display='none';
				document.getElementById("ZIpcoDE").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("ZIpcoDEError") != null)
			{
				document.getElementById("ZIpcoDEError").innerHTML="<br>Please Type Your Zipcode.";
				document.getElementById("ZIpcoDEError").style.display='';
				document.getElementById("ZIpcoDE").ClassName="RedClass";
				document.getElementById("ZIpcoDE").focus();
				return false;
			}
		}
	}




	if(document.getElementById("MOBIle") != null)
	{
		if(document.getElementById("MOBIle").value != '')
		{
			if(document.getElementById("MOBIle").value.search(PhonEVAlidation) >= 0)
			{
				document.getElementById("MOBIleError").innerHTML="<br>Invalid Cell Phone Number.";
				document.getElementById("MOBIleError").style.display='';
				document.getElementById("MOBIle").ClassName="RedClass";
				document.getElementById("MOBIle").focus();
				return false;
			}
			var str =Trim(document.getElementById("MOBIle").value);
			if( str=='')
			{
				document.getElementById("MOBIleError").innerHTML="<br>Please Dont Give Space In Mobile Phone Field.";
				document.getElementById("MOBIleError").style.display='';
				document.getElementById("MOBIle").ClassName="RedClass";
				document.getElementById("MOBIle").value="";
				document.getElementById("MOBIle").focus();
				return false;
			}
			else
			{
				document.getElementById("MOBIleError").innerHTML="";
				document.getElementById("MOBIleError").style.display='none';
				document.getElementById("MOBIle").ClassName="NormalClass";		
			}
		}
		else
		{
			if(document.getElementById("MOBIleError") != null)
			{
				document.getElementById("MOBIleError").innerHTML="<br>Please Type Your Mobile Phone Number.";
				document.getElementById("MOBIleError").style.display='';
				document.getElementById("MOBIle").ClassName="RedClass";
				document.getElementById("MOBIle").focus();
				return false;
			}
		}
	}
return true;	


}
